package org.six11.olive3.server;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.six11.util2.Debug;

/**
 * 
 * 
 * @author Gabe Johnson <johnsogg@cmu.edu>
 */
public class WtfHandler extends WebActionHandler {

  public WtfHandler(String jspPage, WebActionServlet webActionServlet) {
    super(jspPage, webActionServlet);
  }
  
  /**
   * 
   */
  public void service(HttpServletRequest req, HttpServletResponse resp, ServletContext context) throws ServletException,
      IOException {

    Map params = req.getParameterMap();
    Map<String, String> spaceSeparated = new HashMap<String, String>();
    
    HttpSession session = req.getSession();
    for (Object key : params.keySet()) {
      String[] vals = (String[]) params.get(key);
      StringBuffer buf = new StringBuffer();
      for (String v : vals) {
        buf.append(" " + v);
      }
      spaceSeparated.put((String) key, buf.toString().trim());
    }
    session.setAttribute("things", spaceSeparated);
    
    go(req, resp, context);
    // // The following is sample code for setting session values and redirecting to a display page.
    // session.putValue("shopping.shoppingcart", buylist);
    // String url="/jsp/shopping/EShop.jsp";
    // ServletContext sc = getServletContext();
    // RequestDispatcher rd = sc.getRequestDispatcher(url);
    // rd.forward(req, res);

  }

}
